<?php
namespace Api\Controller;
use Think\Controller;
class IndexController extends HomeController {
	public function _initialize(){
		parent::_initialize();
		
		if($this -> _site['myshop']==1){
			// 查询店中店信息,自己有则显示自己的，自己没有则显示参数中的
			$shop = M('myshop') -> find($this -> user['id']);
			if(!$my_shop && $_GET['parent']){
				$shop = M('myshop') -> find(intval($_GET['parent']));
			}
			$this -> assign('shop', $shop);
		}
	}
	//发送短信验证码
	public function send_ver(){
		$mobile = I('request.mobile', 'htmlspecialchars');
		$module = I('request.module', 'htmlspecialchars');
		$token = I('request.token', 'htmlspecialchars');
		if($module==null){
			error("有参数为空");
		}
		if($module == 0 || $module == 7){
			if(empty($mobile)){
				error("有参数为空");
			}
		}else{
			if(empty($token)){
				error("有参数为空");
			}
			$login_info = _check_login($token);
			
	    	$userObj = M("User");
	    	$user_info = $userObj->find($login_info['user_id']);
			$mobile = $user_info['mobile'];
		}
		$c_where['mobile'] = $mobile;
		$c_where['create_time'] = array("gt",NOW_TIME-60);
		$count = M('Ver_log')->where($c_where)->count();
		if($count>0){
			error("超出间隔时间内限制条数");
		}
		$c_where['mobile'] = $mobile;
		$c_where['create_time'] = array("gt",NOW_TIME-3600);
		$count = M('Ver_log')->where($c_where)->count();
		if($count>7){
			error("超出间隔时间内限制条数");
		}
		
        $result = _send_ver($module, $mobile);
        if (isset($result->code)){
        	error("发送失败");
        }
        success("发送成功");
    }
    // 上报设备id
    public function report_device_id()
    {
    	$token=I("request.token");
    	$device_id=I("request.device_id");
    	if(empty($token) || empty($device_id)){
    		error("有参数为空");
    	}
    	$userLoginObj=M("User_login");
    	$login_info = _check_login($token);
    	//清空当前设备值
    	$device_where['token']=$token;
    	$device_date['device_id']=$device_id;
    	$result = $userLoginObj->where($device_where)->save($device_date);
    	//更新设备id
    	/* $arr_save=array(
    			'device_id'=>$str_device_id,
    			'update_time'=>time(),
    	);
    	$obj_t->where($arr_where)->save($arr_save); */
    	if($result !== false)
    	{
    		success('成功');
    	}
    	else
    	{
    		error('失败');
    	}
    }
    
}?>